﻿Option Explicit On

Imports System.Data
Imports System.Text
Imports System.IO
Imports System.Reflection
Imports System.Windows.Media.Animation
Imports Global_Visas_Business_Layer
Partial Public Class frmReportViewer
    Dim reportViewer As New CrystalDecisions.Windows.Forms.CrystalReportViewer
    Private RepGen As New Reports
    Dim ProgressReport As ProgressBar
    'Protected WithEvents rptCommission As CRMReports.Commission

    Private Property ReportData() As Object
        Get
            Return My.Settings.ReportData
        End Get
        Set(ByVal value As Object)
            My.Settings.ReportData = value
            My.Settings.Save()
        End Set
    End Property

    Private Property CurrentReport() As Reports.ReportType
        Get
            Return My.Settings.CurrentReport
        End Get
        Set(ByVal value As Reports.ReportType)
            My.Settings.CurrentReport = value
            My.Settings.Save()
        End Set
    End Property

    Private ReadOnly Property Criteria() As Reports.ReportCriteria
        Get
            'Return CType(My.Settings.ReportCriteria, Reports.ReportCriteria)
            Return GlobalCRM.ReportCriteriaNew
        End Get
    End Property

    Private Sub frmReportViewer_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        'GeneralTasks.ChangeTheme(Me)
        reportViewer = New CrystalDecisions.Windows.Forms.CrystalReportViewer()
        ' Me.reportViewer.ReportSource = Me.ReportData
        'Me.ShowProgressBar()   
        Dim reportProgress As New frmProgressBar()
        reportProgress.TextToDisplay = "Dear " & GlobalCRM.CurrentConName & ", please wait while CRM loads the report for you....."
        reportProgress.Show()
        Me.GenerateReport()
        ReportWindowsFormsHost.Child = reportViewer
        reportProgress.Close()
    End Sub
    Private Sub ShowProgressBar()
        ProgressReport = New ProgressBar()
        Me.ProgressReport.Width = 400
        Me.ProgressReport.Height = 15
        Dim duration As New Duration(TimeSpan.FromSeconds(1))
        Dim doubleanimation As New DoubleAnimation(100.0, duration)
        doubleanimation.RepeatBehavior = RepeatBehavior.Forever
        Me.ProgressReport.BeginAnimation(ProgressBar.ValueProperty, doubleanimation)
        Me.ProgressReport.Visibility = Windows.Visibility.Visible
        Me.Content = ProgressReport
        'StatusBar1.Items.Add(ProgressReport)
    End Sub

    Private Sub GenerateReport()
        Try
            Dim Rpt As CrystalDecisions.CrystalReports.Engine.ReportDocument = Nothing
            'Dim Rpt1 As CrystalDecisions.Windo= Nothing
            ' Dim SQL As StringBuilder
            With Me.reportViewer

                Select Case Me.CurrentReport

                    Case Reports.ReportType.Commission

                        Rpt = New Commission
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\Commission.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.Commission))
                        End With


                    Case Reports.ReportType.InvoiceList

                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New InvoiceList
                        With Rpt
                            ' .FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\InvoiceList.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.InvoiceList))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"
                            .DataDefinition.FormulaFields("Consultant").Text = "'" & Me.Criteria.Consultant_Name & "'"
                            .DataDefinition.FormulaFields("Product").Text = "'" & Me.Criteria.Product_Name & "'"



                        End With

                    Case Reports.ReportType.InvoiceListV2

                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New InvoiceListV2
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\InvoiceListV2.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.InvoiceListV2))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"
                            .DataDefinition.FormulaFields("Consultant").Text = "'" & Me.Criteria.Consultant_Name & "'"
                            .DataDefinition.FormulaFields("Product").Text = "'" & Me.Criteria.Product_Name & "'"

                        End With

                    Case Reports.ReportType.CashUp


                        Rpt = New CashUp
                        With Rpt
                            ' .FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\CashUp.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.CashUp))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"
                            .DataDefinition.FormulaFields("Consultant").Text = "'" & Me.Criteria.Consultant_Name & "'"
                            .DataDefinition.FormulaFields("Product").Text = "'" & Me.Criteria.Product_Name & "'"
                        End With

                    Case Reports.ReportType.EventSummaryConsultant

                        ' Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New EventSummaryCon
                        With Rpt
                            ' .FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\EventSummaryCon.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.EventSummaryConsultant))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"
                            .DataDefinition.FormulaFields("Consultant").Text = "'" & Me.Criteria.Consultant_Name & "'"
                        End With


                    Case Reports.ReportType.FeedbackReport

                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New FeedbackReport
                        With Rpt
                            .FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\FeedbackReport.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.FeedbackReport))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"
                        End With


                    Case Reports.ReportType.PriceList

                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New PriceList
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\PriceList.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.PriceList))
                        End With

                    Case Reports.ReportType.CaseStages

                        '  Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New CaseStages
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\CaseStages.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.CaseStages))
                        End With

                    Case Reports.ReportType.PipelinePreSale

                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New PipelinePreSale
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\PipelinePreSale.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.PipelinePreSale))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"
                            .DataDefinition.FormulaFields("Consultant").Text = "'" & Me.Criteria.Consultant_Name & "'"
                            .DataDefinition.FormulaFields("Product").Text = "'" & Me.Criteria.Product_Name & "'"
                        End With

                    Case Reports.ReportType.SalesStatusSummary

                        ' Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New SalesStatusSummary
                        With Rpt
                            ' .FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\SalesStatusSummary.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.SalesStatusSummary))
                            .DataDefinition.FormulaFields("Consultant").Text = "'" & Me.Criteria.Consultant_Name & "'"
                            .DataDefinition.FormulaFields("Product").Text = "'" & Me.Criteria.Product_Name & "'"
                        End With

                    Case Reports.ReportType.VisasExpiring

                        ' Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New VisasExpiring
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\VisasExpiring.rpt"
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.VisasExpiring))
                        End With

                    Case Reports.ReportType.OpenCasesNoInvoice

                        ' Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New OpenCasesNoInvoice
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\OpenCasesNoInvoice.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.OpenCasesNoInvoice))
                            .DataDefinition.FormulaFields("Consultant").Text = "'" & Me.Criteria.Consultant_Name & "'"
                            .DataDefinition.FormulaFields("Product").Text = "'" & Me.Criteria.Product_Name & "'"
                        End With

                    Case Reports.ReportType.EnteredBySummary

                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New EnteredBySummary
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\EnteredBySummary.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.EnteredBySummary))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"
                        End With

                    Case Reports.ReportType.MigrationCaseStages

                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New MigrationCaseStages
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\MigrationCaseStages.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.MigrationCaseStages))
                        End With

                    Case Reports.ReportType.LeadsPerConsultant

                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New LeadsPerConsult
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\LeadsPerConsult.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.LeadsPerConsultant))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"
                        End With

                    Case Reports.ReportType.WebLeadsPerDay

                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument

                        Rpt = New WebLeads
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\WebLeads.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.WebLeadsPerDay))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"
                        End With

                    Case Reports.ReportType.WebSalesPerDay

                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New WebSales
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\WebSales.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.WebSalesPerDay))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"
                        End With
                    Case Reports.ReportType.WebLeadsAssignedToSalespeople
                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New webleadsassignedtosalespeople
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\webleadsassignedtosalespeople.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.WebLeadsAssignedToSalespeople))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"
                        End With

                    Case Reports.ReportType.ConversionByConsultant
                        ' Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New ConversionCon
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\ConversionCon.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.ConversionByConsultant))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"
                        End With

                    Case Reports.ReportType.ConversionRateProduct
                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New ConversionProd
                        With Rpt
                            ' .FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\ConversionProd.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.ConversionRateProduct))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"
                        End With


                    Case Reports.ReportType.WriteOffList
                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New WriteOff
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\WriteOff.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.WriteOffList))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"

                        End With

                    Case Reports.ReportType.WorkInProgress
                        ' Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New WIP
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\WIP.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.WorkInProgress))
                            '.DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"
                            '.DataDefinition.ParameterFields("balance1").Name

                        End With

                    Case Reports.ReportType.CaseWithNoEvents

                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New NoEventsCaseList
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\NoEventsCaseList.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.CaseWithNoEvents))

                            'SQL = New StringBuilder
                            'With Sql
                            '    .append(" Select Case dbo.L_Branch.Branch_Name")
                            '    .append(" FROM         dbo.L_Consultant INNER JOIN")
                            '    .append(" dbo.L_Branch ON dbo.L_Consultant.Con_BranchID = dbo.L_Branch.Branch_ID")
                            '    .append(" GROUP BY dbo.L_Branch.Branch_Name, dbo.L_Consultant.Con_ID")
                            '    .append(" HAVING(dbo.L_Consultant.Con_ID = " & Me.Criteria.Consultant_Id & ")")
                            'End With

                            ''.DataDefinition.FormulaFields("Consultant").Text = "'" & GlobalCRM.ReportCriteria.Consultant_Name & "'"
                            '.DataDefinition.FormulaFields("Branch").Text = "'" & Me.Criteria.Consultant_Id & "'"
                        End With

                    Case Reports.ReportType.CaseWithOutstandingBalance90
                        ' Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New Outstanding_90
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\Outstanding_90.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.CaseWithOutstandingBalance90))
                        End With

                    Case Reports.ReportType.CaseWithOutstandingBalance60
                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New Outstanding_90
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\Outstanding_90.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.CaseWithOutstandingBalance60))
                        End With

                    Case Reports.ReportType.UserPipeline
                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New PipelineSale
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\PipelineSale.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.UserPipeline))
                        End With

                    Case Reports.ReportType.CasesSubmitted
                        Rpt = New CasesSubmitted
                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\CasesSubmitted.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.CasesSubmitted))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"
                            .DataDefinition.FormulaFields("Consultant").Text = "'" & Me.Criteria.Consultant_Name & "'"
                        End With

                    Case Reports.ReportType.CasesAssigned
                        ' Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New CasesAssigned
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\CasesAssigned.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.CasesAssigned))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"
                            .DataDefinition.FormulaFields("Consultant").Text = "'" & Me.Criteria.Consultant_Name & "'"
                        End With
                    Case Reports.ReportType.DailySalesReport

                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New SalesReport
                        With Rpt
                            .FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\SalesReport.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.DailySalesReport))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"
                            .DataDefinition.FormulaFields("Consultant").Text = "'" & Me.Criteria.Consultant_Name & "'"
                        End With
                    Case Reports.ReportType.WeeklySalesReport
                        ' Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New SalesReport
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\SalesReport.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.WeeklySalesReport))
                            .DataDefinition.FormulaFields("Period").Text = "'" & "This Week" & "'"
                            .DataDefinition.FormulaFields("Consultant").Text = "'" & Me.Criteria.Consultant_Name & "'"
                        End With
                    Case Reports.ReportType.MonthlySalesReport
                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New SalesReport
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\SalesReport.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.MonthlySalesReport))
                            .DataDefinition.FormulaFields("Period").Text = "'" & "This Month" & "'"
                            .DataDefinition.FormulaFields("Consultant").Text = "'" & Me.Criteria.Consultant_Name & "'"
                        End With
                    Case Reports.ReportType.LeadsReportByProduct
                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New LeadsReport
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\LeadsReport.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.LeadsReportByProduct))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"
                        End With


                    Case Reports.ReportType.PaymentDue30
                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New PaymentDueReport
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\PaymentDueReport.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.PaymentDue30))
                        End With

                    Case Reports.ReportType.PaymentDue60
                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New PaymentDueReport
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\PaymentDueReport.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.PaymentDue60))
                        End With

                    Case Reports.ReportType.PaymentDue90
                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New PaymentDueReport
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\PaymentDueReport.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.PaymentDue90))
                        End With

                    Case Reports.ReportType.PaymentDue30SLA
                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New PaymentDueReportSLA
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\PaymentDueReportSLA.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.PaymentDue30SLA))
                        End With

                    Case Reports.ReportType.PaymentDue60SLA
                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New PaymentDueReportSLA
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\PaymentDueReportSLA.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.PaymentDue60SLA))
                        End With

                    Case Reports.ReportType.PaymentDue90SLA
                        ' Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New PaymentDueReportSLA
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\PaymentDueReportSLA.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.PaymentDue90SLA))
                        End With

                    Case Reports.ReportType.RefundsList
                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New Refunds
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\Refunds.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.RefundsList))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"

                        End With

                    Case Reports.ReportType.CSMCaseStage
                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New CSMCaseStages

                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\CSMCaseStages.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.CSMCaseStage))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"

                        End With

                    Case Reports.ReportType.InvoiceListCase
                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New InvoiceListcase
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\InvoiceListcase.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.InvoiceListCase))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"

                        End With
                    Case Reports.ReportType.CaseAssignedCSM
                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New CasesCSMAssigned
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\CasesCSMAssigned.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.CaseAssignedCSM))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"

                        End With
                    Case Reports.ReportType.LeadsProductType
                        'Rpt = New CrystalDecisions.CrystalReports.Engine.ReportDocument
                        Rpt = New LeadsReportProdType
                        With Rpt
                            '.FileName = Environment.CurrentDirectory.Replace("\bin\Debug", "") + "\Reports\Crystal\LeadsReportProdType.rpt"
                            .SetDataSource(RepGen.GetReportData(Reports.ReportType.LeadsProductType))
                            .DataDefinition.FormulaFields("Period").Text = "'" & Me.Criteria.Period & "'"

                        End With
                End Select



                If Not Rpt Is Nothing Then
                    .ReportSource = Rpt
                    .CreateGraphics()
                    Me.ReportData = Rpt
                End If


            End With

        Catch ex As Exception
            CommonFuncs.ErrorHandler(ex, "frmReportViewer-GenerateReport", False)
            Me.Close()
        End Try
        
    End Sub

    
End Class
